package services;

import java.math.BigDecimal;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.session.SqlSession;

import com.aton.db.SessionFactory;

import models.SystemVUsermenu;
import models.SystemVUsermenuExample;
import models.mapper.SystemVUsermenuMapper;

/**
 * 菜单及权限服务类
 * @author wangshaoming
 *
 */
public class MenuServcie {
	/**
	 * 获取菜单
	 * @param operatorid 
	 * @return
	 */
	public static List<SystemVUsermenu> getMenus(String parentCode, String operatorid) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.INSTANCE.getSqlSession();
		try{
			SystemVUsermenuMapper mapper=ss.getMapper(SystemVUsermenuMapper.class);
			SystemVUsermenuExample example=new SystemVUsermenuExample();
			SystemVUsermenuExample.Criteria c=example.createCriteria();
			if(StringUtils.isEmpty(parentCode)){
				c.andParentidIsNull();
			}
			else{
				c.andParentidEqualTo(parentCode);
			}
			c.andOperatoridEqualTo(operatorid);
			c.andStatusEqualTo(new BigDecimal(0));
			example.setOrderByClause("sort asc");
			return mapper.selectByExample(example);
		}finally{
			ss.close();
		}
	}
	
}
